#include "Log.h"

Log * Log::instance;

Log::Log()
{
}
	
Log &Log::Get()
{
	if (instance == NULL)
		instance = new Log();

	return (*instance);
}

void Log::AddLine(std::string line)
{
	char actTime[128];
	GetTimeFormatA(LOCALE_SYSTEM_DEFAULT, 0, NULL, "HH:mm:ss", actTime, 128);

	std::ofstream file("c:\\export_anim_log.txt", std::ios_base::app | std::ios_base::out);
	file << "[" << actTime << "] " << line.c_str() << std::endl;
	file.close();
}

Log & Log::operator << (const char *value)
{
	std::ofstream file("c:\\export_anim_log.txt", std::ios_base::app | std::ios_base::out);

	if (strcmp(T, value) == 0)
	{
		char actTime[128];
		GetTimeFormatA(LOCALE_SYSTEM_DEFAULT, 0, NULL, "HH:mm:ss", actTime, 128);
		file << "[" << actTime << "] ";
	}
	else
		file << value;

	file.close();

	return (*this);
}

Log & Log::operator << (DWORD value)
{
	std::ofstream file("c:\\export_anim_log.txt", std::ios_base::app | std::ios_base::out);

	file << value;

	file.close();

	return (*this);
}

Log & Log::operator << (int value)
{
	std::ofstream file("c:\\export_anim_log.txt", std::ios_base::app | std::ios_base::out);

	file << value;

	file.close();

	return (*this);
}

Log & Log::operator << (unsigned int value)
{
	std::ofstream file("c:\\export_anim_log.txt", std::ios_base::app | std::ios_base::out);

	file << value;

	file.close();

	return (*this);
}

Log & Log::operator << (float value)
{
	std::ofstream file("c:\\export_anim_log.txt", std::ios_base::app | std::ios_base::out);

	file << std::fixed << value;

	file.close();

	return (*this);
}

const char *Log::T = "__time";